<template>
  <div id="updateHistory" >
    <el-table :data="updatelist">
      <el-table-column property="version" label="版本号" width="75"></el-table-column>
      <el-table-column property="userAccount" label="用户账号" width="120" :key="new Date().getTime()"></el-table-column>
      <el-table-column property="updateTime" label="操作时间" width="151"></el-table-column>
      <el-table-column property="ip" label="操作IP" width="120"></el-table-column>
      <el-table-column label="操作" width="120">
        <template slot-scope="scope">
          <el-button icon="el-icon-edit"
                     type="danger"
                     size="mini"
                     @click="edit(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>


import {ttAPI} from "@/api/ttApi";

export default {
  name: "docHistoryBox",
  props:{
    docId:null
  },
  data(){
    return{
      updatelist:[],
    }
  },
  methods:{
    edit(item){
      console.log(item)
      var xhr = new XMLHttpRequest();
      xhr.open('GET', item.docUrl,true);
      xhr.send(null);
      xhr.onreadystatechange= ()=>{
        setTimeout(()=>{
          this.resetSetItem('updateText',xhr.responseText)
        },500)
      }
      this.$parent.$parent.$parent.openHistory=false
    }
  },
  mounted() {
    this.axios.get(ttAPI.getdocHistory+this.docId)
        .then(res => {
          if (!res.data.code) {
            this.updatelist = res.data.data.records
            for (var i = 0; i < this.updatelist.length; i++) {
              if (this.updatelist[i].userId==null){
                this.updatelist[i].userAccount = "未知"
              }
              else{
                const j=i;
                this.axios.get(ttAPI.getUserAccountbyID + this.updatelist[j].userId)
                    .then(ress => {
                      if (!ress.data.code) {
                        this.updatelist[j].userAccount = (ress.data.data != null) ? ress.data.data : "未知"
                      } else {
                        this.updatelist[j].userAccount = "未知"
                      }
                    })
                    .catch(() => {
                      this.updatelist[j].userAccount = "未知"
                    })
              }

            }

          }
        })
  }
}
</script>

<style scoped>
#updateHistory{
  margin-left: 17%;
}
</style>